<?php

class SQL_Helper
{
	 public static function connectDB(){
		//$username='austral6_fire';
//		$password='GktqxPPI0@5X';
//    	return new PDO("mysql:host=localhost;dbname=austral6_rapidfireleague;charset=utf8", $username, $password, array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
		
		$username='austral6_fire';
		$password='GktqxPPI0@5X';
    	return new PDO("mysql:host=127.0.0.1;dbname=rapidfireleague;charset=utf8", $username, $password, array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

	 }
	 
	 public static function executeQuery($selectQuery){	
	 	$params = array_slice(func_get_args(), 1);	
		
		$stmt=SQL_Helper::connectDB()->prepare($selectQuery);	
		$stmt->execute($params);
		return $stmt->fetchAll(PDO::FETCH_ASSOC);
	 }
	 
	  public static function executeQuerySingle($selectQuery){	
	 	$params = array_slice(func_get_args(), 1);	
		
		$stmt=SQL_Helper::connectDB()->prepare($selectQuery);	
		$stmt->execute($params);
		return $stmt->fetch();
	 }
	
	 public static function executeNonQuery($actionQuery){
		$params = array_slice(func_get_args(), 1);	
		
		$stmt=SQL_Helper::connectDB()->prepare($actionQuery);	
		$stmt->execute($params);
	}
	
	 public static function sql_map ($row,$class){
		$object= new $class;
			foreach(array_keys($row) as $key)
			{
				//echo $key." ".$row[$key];
				$object->$key = $row[$key];
			}
		return $object;
	}
	
	 public static function sql_maps ($rows,$class){
		$objects = array();
		foreach($rows as $row)
		{
			$objects[]=SQL_Helper::sql_map($row, $class);
		}
//		while($arrRecords = mysql_fetch_array($rows)){
//			$object= new $class;
//			foreach(array_keys($arrRecords) as $key){
//				$object->$key = $arrRecords[$key];
//			}
//			$objects[]=$object;
//		}
		return $objects;
	}

}
?>